package com.google.googlemarket.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.google.googlemarket.utils.Logger;

/**
 * Created by Administrator on 2017/9/26.
 */

public class AutoScaleHeightImageView extends ImageView {

	public AutoScaleHeightImageView(Context context, @Nullable AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		MearsureSpecUtil.printMeasureSpec(widthMeasureSpec,heightMeasureSpec);//日志
		Drawable drawable = getDrawable();

		int minimumHeight = drawable.getMinimumHeight();
		int minimumWidth = drawable.getMinimumWidth();

		float scale = (float)minimumHeight / minimumWidth;
		int measureWidth = MeasureSpec.getSize(widthMeasureSpec);
		int measureHight = (int) (measureWidth*scale);
		int makeMeasureSpec = MeasureSpec.makeMeasureSpec(measureHight, MeasureSpec.EXACTLY);
		super.onMeasure(widthMeasureSpec, makeMeasureSpec);
	}
}
